package com.longe.controller;

import com.longe.common.JwtUtil;
import com.longe.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private JwtUtil jwtUtil;

    @RequestMapping("login")
    public Map<String, String> login(@RequestBody User user){

        Map<String, Object> mapInfo = new HashMap<>();
        mapInfo.put("info", user);
        String token = jwtUtil.createJWT("9", user.getName(), mapInfo);
        System.err.println("待返回的token为：" + token);

        Map<String, String> result = new HashMap<>();
        result.put("token", token);
        return result;
    }
}
